Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-rsa

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-rsa

Node.js RSA library

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
774K
increased by7.82%
Maintainers
1
Weekly downloads
 
Created

What is node-rsa?

The node-rsa package is a Node.js library for RSA key generation, encryption, and decryption. It provides a simple and easy-to-use API for working with RSA keys and performing cryptographic operations.

What are node-rsa's main functionalities?

Key Generation

This feature allows you to generate a new RSA key pair. The code sample demonstrates how to create a 512-bit RSA key pair and export the public and private keys.

const NodeRSA = require('node-rsa');
const key = new NodeRSA({b: 512});
const publicKey = key.exportKey('public');
const privateKey = key.exportKey('private');
console.log('Public Key:', publicKey);
console.log('Private Key:', privateKey);

Encryption

This feature allows you to encrypt data using the RSA public key. The code sample shows how to encrypt a string message and output the encrypted data in base64 format.

const NodeRSA = require('node-rsa');
const key = new NodeRSA({b: 512});
const encrypted = key.encrypt('Hello, World!', 'base64');
console.log('Encrypted:', encrypted);

Decryption

This feature allows you to decrypt data using the RSA private key. The code sample demonstrates how to decrypt the previously encrypted message and output the original string.

const NodeRSA = require('node-rsa');
const key = new NodeRSA({b: 512});
const encrypted = key.encrypt('Hello, World!', 'base64');
const decrypted = key.decrypt(encrypted, 'utf8');
console.log('Decrypted:', decrypted);

Signing

This feature allows you to sign data using the RSA private key. The code sample shows how to create a digital signature for a string message and output the signature in base64 format.

const NodeRSA = require('node-rsa');
const key = new NodeRSA({b: 512});
const signature = key.sign('Hello, World!', 'base64');
console.log('Signature:', signature);

Verification

This feature allows you to verify a digital signature using the RSA public key. The code sample demonstrates how to verify the signature of a message and output whether the signature is valid.

const NodeRSA = require('node-rsa');
const key = new NodeRSA({b: 512});
const signature = key.sign('Hello, World!', 'base64');
const isVerified = key.verify('Hello, World!', signature, 'utf8', 'base64');
console.log('Verified:', isVerified);

Other packages similar to node-rsa

Keywords

FAQs

Package last updated on 22 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc